#!/usr/bin/python
class SUBT:
    def __init__(self, tstr):
        tmp = [ float(e) for e in tstr.split(':')]
        self.t = tmp[0] * 3600 + tmp[1] * 60 + tmp[2]
    def __repr__(self):
        s = "%02.2f" % (self.t % 60)
        m = "%02d" % (int(self.t / 60) % 60)
        h = str(int(self.t / 3600))
        return h+':'+m+':'+s
    def delay(self, d):
        self.t = self.t + d
        if self.t < 0:
            self.t = 0
        return self.__repr__()

import sys
fn = sys.argv[1]
delta = float(sys.argv[2])
res = ""

with open(fn) as f:
    for line in f:
        if line.startswith("Dialogue:"):
            lst = line.split(',')
            lst[1] = SUBT(lst[1]).delay(delta)
            lst[2] = SUBT(lst[2]).delay(delta)
            line = ','.join(lst)
        res += line
f = open(fn, 'w')
f.write(res)
f.close()
